package com.zj.system.controller;

import com.seventh.common.pojo.R;
import com.zj.system.aop.LogAnnotation;
import com.zj.system.pojo.entity.SysMenu;
import com.zj.system.service.MenuSer;
import io.swagger.annotations.ApiModel;
import io.swagger.annotations.ApiModelProperty;
import io.swagger.annotations.ApiParam;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * @program: clms-seventh
 * @description: 左侧动态导航栏的控制层
 * @author: 张静
 * @create: 2021-07-18 20:30
 **/
@RestController

@RequestMapping("system/menu")
@ApiModel(value = "菜单管理控制层",description = "菜单管理控制层")
public class MenuController {
    @Autowired
    private MenuSer menuSer;

    @GetMapping("selFunction")
    @ApiModelProperty("查询用户持有的菜单")
    @LogAnnotation(title ="菜单接口", action ="查询用户持有的菜单",businessType = "1")
    public R menu(){
        return menuSer.selectFunction();
    }

    @GetMapping("sel/{roleId}")
    @ApiModelProperty("根据角色ID查询角色所拥有的菜单")
    @LogAnnotation(title ="菜单接口", action ="查询角色持有的菜单",businessType = "0")
    public R selRole(@ApiParam("角色ID")@PathVariable("roleId") Integer roleId){
        return menuSer.fenFunction(roleId);
    }

    @GetMapping("insMenu/{roleId}")
    @ApiModelProperty("为角色修改所拥有的菜单")
    @LogAnnotation(title ="菜单接口", action ="为角色修改所拥有的菜单",businessType = "1")
    public R insertRole(@ApiParam("角色ID")@PathVariable("roleId") Integer roleId,
                        @ApiParam("菜单ID数组")@RequestParam List<Integer> roleMenus){
        return menuSer.upMenu(roleId, roleMenus);
    }
    /*@PostMapping("sel/{currentPage}/{pageSize}")
    @ApiModelProperty("查询分页菜单")
    public R selR(@ApiParam("当前显示的页码")@PathVariable("currentPage") Integer currentPage,
                  @ApiParam("每页显示的条数")@PathVariable("pageSize") Integer pageSize,
                  @ApiParam("前端传入的搜索数据")@RequestBody MenuVo menuVo){
        return menuSer.sel( pageSize,currentPage, menuVo);
    }*/
    @PutMapping("up/{menuId}/{visible}")
    @ApiModelProperty("更新菜单的状态")
    @LogAnnotation(title ="菜单接口", action ="更新菜单的状态",businessType = "2")
    public R upStatus(@ApiParam("菜单ID")@PathVariable("menuId") Integer menuId,
                      @ApiParam("菜单状态")@PathVariable("visible") Integer visible){
        return menuSer.upStatus(menuId,visible);
    }

    @PutMapping("updateMenuById")
    @ApiModelProperty("修改菜单")
    @LogAnnotation(title ="菜单接口", action ="修改菜单",businessType = "2")
    public R update(@ApiParam("修改的菜单信息")@RequestBody SysMenu menu){
        return menuSer.up(menu);
    }

    @PostMapping("insertMenu")
    @ApiModelProperty("新增菜单")
    @LogAnnotation(title ="菜单接口", action ="新增菜单",businessType = "1")
    public R insertUser(@ApiParam("新增的菜单信息")@RequestBody SysMenu menu){
        return menuSer.ins(menu);
    }

    @GetMapping("selById/{menuId}")
    @ApiModelProperty("根据ID查询菜单信息")
    @LogAnnotation(title ="菜单接口", action ="根据ID查询菜单信息",businessType = "0")
    public R selById(@ApiParam("菜单ID")@PathVariable("menuId") Integer menuId){
        return menuSer.selById(menuId);
    }

    @DeleteMapping("del/{menuId}")
    @ApiModelProperty("根据ID删除菜单")
    @LogAnnotation(title ="菜单接口", action ="根据ID删除菜单",businessType = "3")
    public R del(@ApiParam("菜单ID")@PathVariable("menuId") Integer menuId){
        return menuSer.del(menuId);
    }

    @PostMapping("selMenuName")
    @ApiModelProperty("查询菜单名是否唯一")
    @LogAnnotation(title ="菜单接口", action ="查询菜单名是否唯一",businessType = "0")
    public R selUserName(@ApiParam("菜单信息包含菜单名字")@RequestBody SysMenu menu){
        return menuSer.selMenuName(menu);
    }

    @PostMapping("showParent")
    @ApiModelProperty("查询所有的父级菜单")
    @LogAnnotation(title ="菜单接口", action ="查询所有的父级菜单",businessType = "0")
    public R showParent(@ApiParam("菜单信息包含父菜单ID")@RequestBody SysMenu menu){
        return menuSer.selParentId(menu);
    }

    @GetMapping("menutable")
    @ApiModelProperty("查询所有的菜单")
    @LogAnnotation(title ="菜单接口", action ="查询所有的菜单",businessType = "0")
    public R getMenuTable() {
        return menuSer.getMenuTable();
    }
}
